#include "EditorAbilityView.h"

#include "Object/NewObject.h"
#include "Framework/Editor.h"

#include "Ability/EditorAbilityViewModel.h"
#include "Widgets/TextWidget.h"

void REditorAbilityView::BindViewModel(TSharedObjectPtr<REditorAbilityViewModel> InViewModel)
{
    BaseViewModel = InViewModel;
}

std::function<float()> REditorAbilityView::FillTextTitleBar(TSharedObjectPtr<RWidget> InTitleBar)
{
    auto TextWidget=NewWidget<RTextWidget>(InTitleBar);
    TextWidget->Text=BaseViewModel->GetName();
    RTextWidgetWeakPtr WeakTextWidget=TextWidget;
    std::function<float()> WidthGetter=[WeakTextWidget]()
    {
        return WeakTextWidget->GetTextSize().X+2;
    };

    TextWidget->Width=WidthGetter;
    TextWidget->HorizontalAlignment=ETextHorizontalAlignment::Center;
    TextWidget->Anchor.VerticalFill(InTitleBar);

    return WidthGetter;
}

TSharedObjectPtr<REditorAbilityViewModel> REditorAbilityView::GetBaseViewModel()
{
    return BaseViewModel;
}
